//
// Created by neo on 2025/3/21.
//

#include "ComputeGraphEngine.h"

#include "log/Log.h"

bool ComputeGraphEngine::Initialize() {
    std::vector<const char *> requiredExtensions;
    this->gpuCtx = std::make_shared<VkGPUContext>(requiredExtensions);
    // this->gpuCtx->AddInstanceEnableLayer("VK_LAYER_KHRONOS_validation");
    VkResult result = this->gpuCtx->Init();
    if (result != VK_SUCCESS) {
        Logger() << Logger::ERROR << "Failed to initialize Vulkan GPU context!" << std::endl;
        return false;
    }
    this->computeGraph = std::make_shared<ComputeGraph>(this->gpuCtx);
    result = this->computeGraph->Init();
    if (result != VK_SUCCESS) {
        Logger() << Logger::ERROR << "Failed to initialize ComputeGraph!" << std::endl;
        return false;
    }
    Logger() << Logger::INFO << "Initialized ComputeGraphEngine, version: " << VERSION << std::endl;
    return true;
}

void ComputeGraphEngine::LoadComputeGraph(std::string filePath) {
}

void ComputeGraphEngine::ConstructComputeGraph() {
}

bool ComputeGraphEngine::ExecuteComputeGraph() const {
    const VkResult result = this->computeGraph->Compute();
    if (result != VK_SUCCESS) {
        Logger() << Logger::ERROR << "Failed to execute ComputeGraph!" << std::endl;
        return false;
    }
    return true;
}

void ComputeGraphEngine::DestroyComputeGraph() const {
    this->computeGraph->Destroy();
}
